package xin.printk.android.module.register;

import xin.printk.android.BasicApplication;
import xin.printk.android.R;
import xin.printk.android.data.db.dao.UserDao;
import xin.printk.android.data.entity.User;
import xin.printk.android.utils.LogUtils;
import xin.printk.android.utils.RequestCallback;

public class RegisterModel {

    public void register(String account, String password, RequestCallback callback) {
        long ret = UserDao.register(account, password);
        LogUtils.d("userdao register return " + ret);
        if (ret != -1) {
            User user = UserDao.login(account, password);
            if (user != null) {
                LogUtils.d("register success");
                if (callback != null) {
                    callback.onSuccess(user);
                }
            } else {
                LogUtils.d("register fail");
                if (callback != null) {
                    callback.onFailure(BasicApplication.getContext().getString(R.string.register_error_tips));
                }
            }
        } else {
            LogUtils.e("register return -1");
            if (callback != null) {
                callback.onFailure(BasicApplication.getContext().getString(R.string.register_error_tips));
            }
        }
    }
}
